﻿
@{
    ViewBag.Title = "编辑分档方案";
    Layout = "~/Views/Shared/_LayoutPage.cshtml";
}
@model IOA.MES.DataAccess.VModel.VBinningSchema

@section Contents{
    <style>
        html {
            background-color: #FFF;
        }

        .layui-form-item .layui-input-inline {
            width: 300px;
        }
    </style>
}

<div id="page"></div>

<template id="tplPage">
    <div class="layui-form" lay-filter="layuiadmin-app-form-list" style="padding: 20px 30px;">
        <div class="layui-form-item">
            <label class="layui-form-label" v-html="lang.Field.Name">方案名称：</label>
            <div class="layui-input-inline">
                <input type="text" lay-verify="required" placeholder="请输入登录名" name="SchemaName" value="@(Model?.SchemaName??string.Empty)" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label" v-html="lang.Field.WorkShop">用户车间：</label>
            <div class="layui-input-inline">
                <select id="selWorkshops" name="WorkshopCode" lay-filter="selWorkshops">
                    @foreach (var item in ViewBag.Workshops as List<IOA.MES.DataAccess.VModel.VWorkshop>)
                    {
                        <option value="@item.WorkshopCode" @(Model != null && Model.WorkshopCode == item.WorkshopCode ? " selected" : "")>@item.WorkshopName</option>
                    }
                </select>
            </div>
        </div>
        <div class="layui-form-item" style="text-align:center;padding-top: 20px;">
            <input type="hidden" name="PkId" value="@(Model?.PkId??0)">
            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="submit"><i class="layui-icon">&#xe605;</i>保存</button>
            <button class="layui-btn layui-btn-primary" onclick="parent.layer.close(parent.layer.getFrameIndex(window.name));"><i class="layui-icon">&#xe616;</i>取消</button>
        </div>
    </div>
</template>

@section Scripts{
    <script>
        var vm = new Vue({
            el: "#page",
            template: "#tplPage",
            data: {
                lang: JSON.parse(lang).package
            }
        });

        setTimeout(function () {
            initLayui();
        }, 50);

        function initLayui() {
            layui.use(['form', 'layer', 'index'], function () {
                var layer = layui.layer,
                    form = layui.form;

                form.on('submit(submit)', function (data) {
                    var loadId = layer.load();
                    $.ajax({
                        url: "/ParaSetting/SaveBinningSchema",
                        data: {
                            model: data.field,
                        },
                        complete: function () {
                            layer.close(loadId);
                        },
                        success: function (res) {
                            if (res.ErrCode != 200) {
                                layer.msg(res.ErrMsg, { icon: 5 });
                                return;
                            }
                            layer.msg("保存成功！", { icon: 6, time: 1500 }, function () {
                                parent.layer.close(parent.layer.getFrameIndex(window.name));
                            });
                        }
                    });
                    return false;
                });
            });
        }
    </script>
}
